<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'挂卖销售记录'),
); 
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_yangjidan_myjiorder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['address']=json_decode($item['address'],true);
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['title']=$this->getcolumn('myji',array('id'=>$item['jiid'],'merchid'=>$_SESSION['onemerchid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'购买者','type'=>'member'),
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'title','title'=>'蛋鸡名称','type'=>'string'),
			array('type'=>'string','title'=>'联系人','name'=>'name'),
			array('type'=>'string','title'=>'联系电话','name'=>'mobile'),
			array('type'=>'string','title'=>'收货地址','name'=>'address.address'),
			array('name'=>'price','title'=>'购买价格','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('op'=>'fa','title'=>'发货','type'=>'href','show'=>array('status'=>array(1,21))),		
		)),
		'search'=>array(
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['status']=$this->myjiorder_status;
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='fa'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('参数错误！','error');
		}
		if(!$post['express_id'] || !$post['expresssn']){
			exi('请填写快递信息','error');
		}
		pdo_update('jy_yangjidan_myjiorder',array('status'=>2,'express_id'=>$post['express_id'],'expresssn'=>$post['expresssn']),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('已发货！','','/myjiorder/');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_yangjidan_myjiorder',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$htmls=array(
		'type'=>'edit',
		'desc'=>'订单发货',
	);
	$tip='商品订单已打包好,快递发货！';
	$item['address']=json_decode($item['address'],true);
	$htmls['edit']=array(
		array('type'=>'tip','title'=>$tip),
		array('type'=>'copy','title'=>'联系人','name'=>'address.name'),
		array('type'=>'copy','title'=>'联系电话','name'=>'address.mobile'),
		array('type'=>'copy','title'=>'收货地址','name'=>'address.address'),
		array('type'=>'select','title'=>'快递公司','name'=>'express_id','options'=>'express','option_title'=>'name'),
		array('type'=>'string','title'=>'快递单号','name'=>'expresssn'),
	);
	$return['express']=model('jy_weishop/model')->express_types();
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
